package cn.wolfcode.edu.web.controller;

import cn.wolfcode.edu.domain.SystemDictionaryItem;
import cn.wolfcode.edu.service.ISystemDictionaryItemService;
import cn.wolfcode.edu.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
<<<<<<< HEAD
 * Created by ASUS on 2018/7/9.
=======
 * Created by abb on 2018-07-11.
>>>>>>> sun
 */
@Controller
@RequestMapping("systemDictionaryItem")
public class SystemDictionaryItemController {
    @Autowired
    private ISystemDictionaryItemService systemDictionaryItemService;

    @RequestMapping("delete")
    @ResponseBody
    public JsonResult delete(Long id){
        JsonResult result = new JsonResult();
        try{
            systemDictionaryItemService.deleteByPrimaryKey(id);
        }catch(Exception e){
            e.printStackTrace();
            result = new JsonResult("有错误");
        }
        return result;

    }

    @RequestMapping("")
    public String index(){
        return "/systemDictionaryItem";
    }


    @RequestMapping("list")
    @ResponseBody
    public List<SystemDictionaryItem> list() {
        return systemDictionaryItemService.selectAll();
    }
    @RequestMapping("listItem")
    @ResponseBody
    public List<SystemDictionaryItem> listItem(Long id) {
        return systemDictionaryItemService.selectItem(id);
    }

    @RequestMapping("save")
    @ResponseBody
    public JsonResult save(SystemDictionaryItem systemDictionaryItem){
        JsonResult jsonResult = new JsonResult();
        try {
            systemDictionaryItemService.insert(systemDictionaryItem);

        }catch (Exception e){
            e.printStackTrace();
            jsonResult.setMsg("get wrong");
        }
        return jsonResult;
    }
    //提交保存员工 { success:true,msg:""}
    @RequestMapping("update")
    @ResponseBody

    public JsonResult update(SystemDictionaryItem systemDictionaryItem){
        JsonResult jsonResult = new JsonResult();
        try {
            systemDictionaryItemService.updateByPrimaryKey(systemDictionaryItem);
        }catch (Exception e){
            e.printStackTrace();
            jsonResult.setMsg("get wrong");
        }
        return jsonResult;
    }


    //查询所有
    @RequestMapping("listAllItemBySn")
    @ResponseBody
    public List<SystemDictionaryItem> listAllItemBySn(String sn){
        return systemDictionaryItemService.listAllItemBySn(sn);
    }

}
